package com.dinggou.shopjb.view;

import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;


import com.dinggou.shopjb.R;
import com.dinggou.shopjb.adapters.PopupGroupAdapter;
import com.dinggou.shopjb.base.BaseActivity;
import com.dinggou.shopjb.base.BasePopUpWindow;
import com.zc.mychart.model.GoodsAllBean;

import java.util.List;


public class ProGroupBeanPopupWindow extends BasePopUpWindow implements View.OnClickListener {


    private ProGroupListener mListener;
    private BaseActivity mActivity;
    private GridView gv_product;
    private PopupGroupAdapter mAdapter;

    public ProGroupBeanPopupWindow(BaseActivity a, ProGroupListener listener) {
        super(a, R.layout.layout_popup_pro_bean);
        setBackgroundColor(0x00000000);
        this.mActivity = a;
        this.mListener = listener;
        gv_product = getPopUpView().findViewById(R.id.gv_product);
        getPopUpView().setOnClickListener(this);
        setGv_product();

    }

    private void setGv_product() {
        final List<GoodsAllBean> mProGroupBeanList = mActivity.myApplication.getAllList();
        if (null == mAdapter){
            mAdapter = new PopupGroupAdapter(mActivity, mProGroupBeanList);
            gv_product.setAdapter(mAdapter);
        }
        gv_product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                GoodsAllBean bean = mProGroupBeanList.get(position);
                mAdapter.setChecked(position);
                mAdapter.notifyDataSetChanged();
                mListener.onClickProduct(bean.pro_name, bean.pro_code);
                dismiss();
            }
        });
    }

    public void resetChoose() {
        mAdapter.setChecked(-1);
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }

    public interface ProGroupListener {
        void onClickProduct(String name, String code);
    }
}
